package com.zhang.common.security.handle;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * @ClassName AbstractAuthenticationFailureEvenHandler
 * @Description 认证失败事件处理器
 * @Author zsw
 * @Date 2019/10/28 16:39
 * @Version V1.0
 **/

public abstract class AbstractAuthenticationFailureEvenHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent applicationEvent) {
        AuthenticationException authenticationException = applicationEvent.getException();
        Authentication authentication = (Authentication) applicationEvent.getSource();

        handle(authenticationException, authentication);
    }


    /**
     * @Author zsw
     * @Description  处理登录失败方法
     * @Date 2019/10/28 16:43
     * @param authenticationException
     * @param authentication
     * @return void
     */
    public abstract void handle(AuthenticationException authenticationException, Authentication authentication);
}